- /* sxmsetdb.cpp by K.Tsuru */
- // function ID = 501 BRADIX
- #ifndef SN_H
- #include "sn.h"
- #endif
- /*************************************************************
- SDecimal class
- Provides a radix conversion
- double ---> BRADIX
- Used in the substitution of double type including long type.
- *************************************************************/
- void SDecimal::SetXDouble(double d){
- if(d == 0.0){
- SetZero(); return;
- }
- /***************************************************************************
- A finite binary decimal such as ldexp(1.5, -400) = 1.5*2^(-400) must be
- converted exactly.If this is treated in the decimal radix(DRADIX) an
- inacurate value is supplied because of taiking into account fifteen
- effective figures only.On the other hand if an infinite binary decimal such
- as 0.1 are converted to a binary decimal in 53 bits it may be contrary to
- user's expectations.In this case it converts once the value into DRADIX,
- next into BRADIX.
- A decimal ldexp(f, -400) whose f has more than 30 bits cannot be converted
- exactly? It is difficult to judge whether it must be converted into infinite
- or finite decimal.
- ***************************************************************************/
- uint sz;
- //Convert |d| into a value with binary radix(BRADIX). This can be performed
- //exactly for any value.
- int bfig = DOUBLE_BITS/BRADIX_BITS; // = 53bits/15 = 3.5figures
- int f = doubleToBinDec(fabs(d), figure, &sz);
-
- if(f < 0) SetError(OVERFLOW_ERR, "SetXDouble",501);
- if(f < bfig){//within two figures in BRADIX(30bits) for safety.
- // |d| = I.abcd efgh 0000 abcd efgh .... can be existent.
- aTail = 0;
- sz = min(sz, MaxSize());
- while( (figure(aTail)== 0) && (aTail < sz) ) aTail++;
- // d is very small and can be regarded as zero within present accuracy.
- if(aTail == sz){
- SetZero(); return;
- }
- aHead = sz-1u; while(figure(aHead)== 0) aHead--;
- SetSign(d);
- return;
- }
- //Here it may be an infinite decimal in BRADIX.
- SDouble a(d); //convert into DRADIX
- SDecimal tmp; // Changes called by object since version 2.20
- *this = tmp.ConvToBin(a); //convert into BRADIX
- }
sxmsetdb.cpp : last modifiled at 2015/12/15 14:05:33(2,143 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).